using Glpt.Data;
using System.Data;

namespace GTask
{
    /// <summary>
    /// 参数设置类
    /// </summary>
    public class ParamList
    {
        private static DataSet dset = null;
        private static string filename = "params_list.xmlzip";

        static ParamList()
        {
            dset = new DataSet();
            if (System.IO.File.Exists(AbstractInterFace.StartupPath + filename))
            {
                dset = DataSetIO.ReadDataSetFromXmlZip(AbstractInterFace.StartupPath + filename);
            }
            DataTable dt = null;
            if (dset.Tables.Count == 0)
            {
                dt = new DataTable("ParamTable");
                dset.Tables.Add(dt);
            }
            else
                dt = dset.Tables["ParamTable"];
            if (!dt.Columns.Contains("NO"))
                dt.Columns.Add("NO", typeof(int));
            if (!dt.Columns.Contains("SecondOut"))
                dt.Columns.Add("SecondOut", typeof(int));
            if (!dt.Columns.Contains("SecondIn"))
                dt.Columns.Add("SecondIn", typeof(int));
            if (!dt.Columns.Contains("MaxTaskCount"))
                dt.Columns.Add("MaxTaskCount", typeof(int));
            if (dt.Rows.Count == 0)
                dt.Rows.Add(dt.NewRow());
        }

        /// <summary>
        /// 初始化类的新实例
        /// </summary>
        private ParamList()
        {
        }

        /// <summary>
        /// 获取参数表
        /// </summary>
        public static DataTable ParamTable
        {
            get
            {
                return dset.Tables["ParamTable"];
            }
        }

        /// <summary>
        /// 获取参数信息
        /// </summary>
        public static string GetParamData(string columnname)
        {
            return ParamTable.Rows[0][columnname].ToString();
        }

        /// <summary>
        /// 设置参数信息
        /// </summary>
        public static void SetParamData(string columnname, string value)
        {
            ParamTable.Rows[0][columnname] = value;
        }

        /// <summary>
        /// 保存
        /// </summary>
        public static void Save()
        {
            DataSetIO.SaveDataSetToXmlZip(dset, AbstractInterFace.StartupPath + filename);
        }
    }
}
